package com.example.demo.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.example.demo.dto.SearchInfo;
import com.example.demo.entity.Cangku;



@Repository()
public interface Cangku_Mapper extends BaseMapper<Cangku>{
	
	@Select("SELECT cangku.* "
	        + "FROM cangku  ${where} ${limitstr}")
	public List<Cangku> select(SearchInfo info);
	
	@Select("SELECT COUNT(1) FROM cangku ${where}")
	public long selectCount(SearchInfo info);
	
	@Insert("INSERT INTO cangku (chanpinname, leibie, jiliangdanwei, chandi,shuliang) VALUES (#{chanpinname}, #{leibie}, #{jiliangdanwei}, #{chandi},#{shuliang})")
	public void insert(Cangku cangku);
	
	@Update("UPDATE cangku SET chanpinname = #{chanpinname}, leibie = #{leibie}, "
	        + "jiliangdanwei = #{jiliangdanwei}, chandi = #{chandi},shuliang=#{shuliang} WHERE id = #{id}")
	public void update(Cangku cangku);
	
	
	@Delete("DELETE FROM cangku WHERE id = #{id}")
	public void delete(int id);
	
	@Select("SELECT * FROM cangku WHERE id = #{id}")
	public Cangku selectById(int id);

	@Update("UPDATE cangku SET shuliang = (shuliang+#{shuliang}) where id = #{id}")
	void tianjiashuliang(int id ,int shuliang);

	@Update("UPDATE cangku SET shuliang = (shuliang-#{shuliang}) where id = #{id}")
	void jianshaoshuliang(int id, int shuliang);
}
